﻿using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using Neptuno.Component;
using System.Runtime.Serialization;
using Neptuno.Model;

namespace Neptuno.Service
{
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    public class BuquesService
    {
        BuquesComponent Component = new BuquesComponent();

        [WebInvoke(UriTemplate = "", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public Buques AgregarBuque(Buques Buque)
        {
            return Component.Agregar(Buque);
        }

        [WebGet(UriTemplate = "{skip}/{range}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public List<Buques> Listar(string skip = null, string range = null)
        {
            int? Skip = !string.IsNullOrWhiteSpace(skip) ? new int?(int.Parse(skip)) : null;
            int? Range = !string.IsNullOrWhiteSpace(range) ? new int?(int.Parse(range)) : null;

            return Component.Listar(true, Skip, Range);
        }

        [WebGet(UriTemplate = "", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public List<Buques> ListarTodos()
        {
            return this.Listar(null, null);
        }

        [WebGet(UriTemplate = "Eliminados", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public List<Buques> ListarEliminados()
        {
            return Component.Listar(false);
        }

        [WebGet(UriTemplate = "ByLinea/{id}/{skip}/{range}", ResponseFormat = WebMessageFormat.Json)]
        public List<Buques> ListarByLinea(string id, string skip, string range)
        {
            int? Skip = !string.IsNullOrWhiteSpace(skip) ? new int?(int.Parse(skip)) : null;
            int? Range = !string.IsNullOrWhiteSpace(range) ? new int?(int.Parse(range)) : null;

            return Component.Listar(int.Parse(id), Skip, Range);
        }

        [WebGet(UriTemplate = "ByLinea/{id}", ResponseFormat = WebMessageFormat.Json)]
        public List<Buques> ListarTodosByLinea(string id) {
            return this.ListarByLinea(id, null, null);
        }

        [WebGet(UriTemplate = "{id}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public Buques GetById(string id)
        {
            return Component.GetById(int.Parse(id));
        }

        [WebInvoke(UriTemplate = "", Method = "PUT", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public bool Actualizar(Buques Buque)
        {
            return Component.Actualizar(Buque);
        }

        [WebGet(UriTemplate = "Restaurar/{id}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public bool Restaurar(string id)
        {
            return Component.Habilitar(int.Parse(id));
        }

        [WebInvoke(UriTemplate = "{id}", Method = "DELETE", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        public void Borrar(string id)
        {
            Component.Borrar(int.Parse(id));
        }
    }
}